<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<script src="../js/head_public.js"></script>
		<script src="../js/session.js"></script>
		<script src="../js/common.js"></script>
		<style>
			.yirenzheng{background:#ff7e00;border-radius: 0.5rem;border: none!important;color: #fff!important;margin-top: 0.8rem;}
		    .gengxin{font-size: 0.3rem;color: #666;margin-top: 0.8rem;display: inline-block;}
		    .ding-code{font-size: 14px;color: #666666;border-bottom: 1px solid #EEEEEE;}
		    .ds-name{padding-left: 40px;font-size: 0.35rem;font-weight: normal;color: #323232;background: url(../images/shaoshi-icon.png)no-repeat;background-size: 30px;background-position: 0rem -0.1rem;margin: 0px;height: 25px;line-height: 25px;}
		    .ds-container{overflow: hidden;margin-top:0.2rem ;position: relative;}
		    .gm-jifen{position: absolute;top:0.7rem;left: 2.2rem;color: #ff7e00!important;font-size: 14px;}
		    .money{font-size: 0.4rem;}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">待付款</h1>
		</header>
		<div class="mui-content" style="padding-bottom: 0px;">
			<div class="gwc-adress-container">
		    	<!--<h1 class="mui-navigate-right">收货地址<img src="../images/mdate_right.png" style="float: right;width: 0.5rem;"></h1>
		    	<p class="person-icon"><span>收货人：王潇潇</span><span>18193186350</span></p>
		    	<p class="ads-icon">地址：甘肃省兰州市七里河区西湖公园甘肃省兰州市七里河区西湖公园</p>-->
		    </div>
	    	<ul class="store-list">
	    		<!--<li>
	    			<a data-href="" style="display: block;">
	    				<h2 class="ds-name">兰州新辉商店</h2>
	    				<!--<div class="ding-code">订单编号：1234567894561233</div>-->
	    				<!--<div class="ds-container">
	    					<img  src="../images/goods.png"/>
		    				<div class="store-con">
		    					<h1 class="only-line" style="overflow: hidden;">兰州新辉商店<span class="order-p">￥19.9</span></h1>
		    					<span class="gengxin">共1件商品</span><span class="shifu">实付：<b>￥19.7</b></span>
		    					<!--<img src="../images/phone.png"  class="gm-phone-icon"/>-->
		    				     <!--<span class="gm-phone-icon" style="color: #666666;">x1</span>
		    				</div>
	    				</div>
	    				<div class="ds-container">
	    					<img  src="../images/goods.png"/>
		    				<div class="store-con">
		    					<h1 class="only-line" style="overflow: hidden;">兰州新辉商店<span class="order-p">￥19.9</span></h1>
		    					<span class="gengxin">共1件商品</span><span class="shifu">实付：<b>￥19.7</b></span>
		    					<!--<img src="../images/phone.png"  class="gm-phone-icon"/>-->
		    				     <!--<span class="gm-phone-icon" style="color: #666666;">x1</span>
		    				</div>
	    				</div>-->
	    			
	    			<!--</a>

	    		</li>-->
	    		<!--<li>
	    			<a data-href="" style="display: block;">
	    				<h2 class="ds-name">兰州新辉商店</h2>
	    				<div class="ding-code">订单编号：1234567894561233</div>
	    				<div class="ds-container">
	    					<img  src="../images/goods.png"/>
		    				<div class="store-con">
		    					<h1 class="only-line" style="overflow: hidden;">兰州新辉商店<span class="order-p">￥19.9</span></h1>
		    					<span class="gengxin">共1件商品</span><span class="shifu">实付：<b>￥19.7</b></span>
		    					
		    				    <span class="gm-phone-icon" style="color: #666666;">x1</span>
		    				     <span class="gm-jifen" style="color: #666666;">10积分</span>
		    				</div>
	    				</div>
	    				<div class="ds-container">
	    					<img  src="../images/goods.png"/>
		    				<div class="store-con">
		    					<h1 class="only-line" style="overflow: hidden;">兰州新辉商店<span class="order-p">￥19.9</span></h1>
		    					<span class="gengxin">共1件商品</span><span class="shifu">实付：<b>￥19.7</b></span>
		    					
		    				    <span class="gm-phone-icon" style="color: #666666;">x1</span>
		    				</div>
	    				</div>       				
	    			</a>
	    		</li>-->
	    	</ul>
	    	    <div style="background: #fff;padding-bottom: 10px;" class="zhifu-container1">
	    	         <div class="money" ><span id="money">39.8</span>元<span style="color: #ff7e00;"><span id="pay-jifen"></span>积分</span></div>
	    	         <input id="addressid" type="hidden" />
	    	        <div class="zhifu-type" flag="1" type="wxpay_app">
						<img  src="../images/jiaofei-weixin.png"/>
						<span>微信支付</span>
						<div class="quan"><span></span></div>
					</div>
					<div class="zhifu-type" flag="0" type="alipay_app">
						<img  src="../images/jiafei-zhifubao.png"/>
						<span>支付宝</span>
						<div class="quan"><span style="display: none;"></span></div>
					</div>
					<div class="zhifu-type" flag="0" type="point">
						<img  src="../images/jifen.png"/>
						<span>积分</span>
						<div class="quan"><span style="display: none;"></span></div>
					</div>
					<button class="jiao-btn">确认付款</button>
				</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/jquery-1.8.0.min.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript">
		mui(".zhifu-container1").on("tap",".zhifu-type",function(){
			if($(this).attr("flag")=="0"){
				$(this).attr("flag","1").siblings(".zhifu-type").attr("flag","0");
				$(this).find(".quan span").show().end().siblings(".zhifu-type").find(".quan span").hide();
			}
		})
		var ye=getQueryString("ye");//存放是从购物车进来的还是从详情页面进来的还是从订单中进来的，1：购物车，2，详情页面3，支付订单
		$(function(){
			var car_id="";//存放
			var wxChannel = null; // 微信支付
			var aliChannel = null; // 支付宝支付
			var channel = null;
			//页面加载时
			mui.plusReady(function(){
				//关闭等待框
				plus.nativeUI.closeWaiting();
				plus.payment.getChannels(function(channels){
					for  (var  i  in  channels)  {
			            if  (channels[i].id  ==  "wxpay")  {
			                    wxChannel  =  channels[i];
			            }  else  {
			                    aliChannel  =  channels[i];
			            }
			        }
			    },function(e){
			        alert("获取支付通道失败："+e.message);
			    });
		   });	
			
//			 	检测是否安装支付服务
			function checkServices(pc){
				if(!pc.serviceReady){
					var txt=null;
					switch(pc.id){
						case 'alipay':
						txt='检测到系统未安装“支付宝快捷支付服务”，无法完成支付操作，是否立即安装？';
						break;
						default:
						txt='系统未安装“'+pc.description+'”服务，无法完成支付，是否立即安装？';
						break;
					}
					plus.nativeUI.confirm(txt, function(e){
						if(e.index==0){
							pc.installService();
						}
					}, pc.description);
				}
			}
			var userid=getCookie("userid")
			if(userid==""||userid==null){
				alert("您还没有登录，请先登录")
				location.href="../public/login.html"
			}else{
				var params={};
				params.member_id=userid;
//				params.state_type="10";
				//读取收获地址
         		$.post(net+"/public/index.php?s=api/Cart/address/",{"member_id":userid},function(res){
         			if(res.code=="200"){
         				if(res.result!=null&&res.result.length!=0){
         					var str="";
         					$("#addressid").val(res.result.address_id)
//       					var src=net+"public/uploads/home/store/goods/"+this.store_id+"/"+this.goods_image;
         					str='<h1 >收货地址<img src="../images/mdate_right.png" style="float: right;width: 0.5rem;"id="go-list"></h1><p class="person-icon"><span>收货人：'+res.result.address_realname+'</span><span style="margin-left:5px">'+res.result.address_mob_phone+'</span></p><p class="ads-icon">地址：'+res.result.address_detail+'</p> '
         					$(".gwc-adress-container").append(str);
         				}else{
         					alert("您还没有选择收货地址，请选择收货地址");
         					location.href="address.html?pay=pay&ye="+ye;
         				}
         				mui(".gwc-adress-container").on("tap","#go-list",function(){
         					mui.openWindow({url:"address.html?pay=pay&ye="+ye})
         				})
         			}else if(res.code=="201"){
         				alert("您还没有选择收货地址，请选择收货地址");
         					location.href="address.html?pay=pay&ye="+ye;
         			}
         		})
         		var order_id="";
         		order_id=getQueryString("id");
         		if(order_id!=null&&order_id!=""){
         			$.post(net+"/public/index.php?s=api/memberorder/show_order",{"member_id":userid,"id":order_id},function(res){
         				if(res.code=="200"){
         					var str="";
		         			var sum=0;
		         			var sumjifen=0;//总积分
		         		    console.log(res.result.goods_list)
//		         		
		         				var goodlist='';
		         				if(res.result.goods_list!=null&&res.result.goods_list.length!=0){
		         					$.each(res.result.goods_list, function(index,val) {
		         						sum+=this.goods_price*this.goods_num;
		         						sumjifen+=this.goods_point*this.goods_num;
		         						car_id+=this.goods_id+'_'+this.goods_num+',';
		         						var src=net+"public/uploads/home/store/goods/"+this.store_id+"/"+this.goods_image;
		         						goodlist+='<div class="ds-container"><img  src="'+src+'"/><div class="store-con"><h1 class="only-line" style="overflow: hidden;">'+this.goods_name+'<span class="order-p">￥'
		         						        +this.goods_price+'</span></h1><span class="gengxin">共'+this.goods_num+'件商品</span></span><span class="gm-jifen" style="color: #666666;">'+this.goods_point+'积分</span>'
		         				                +'<span class="gm-phone-icon" style="color: #666666;">x'+this.goods_num+'</span></div></div>'
		         					});
		         				}
//		         			
		         			str+='<li><a data-href="" style="display: block;"><h2 class="ds-name">'+res.result.store_name+'</h2>'+goodlist+'</a></li>'	
		         			sum=Math.round(sum*100)/100;
		         			$("#money").html(sum)
		         			$("#pay-jifen").html('&nbsp;/&nbsp;'+sumjifen)
		         			$(".store-list").append(str)
		         		
         				}
         			})
         		}else{
         			if(ye=='1'){
         				//从cookie中获取订单商品信息
		         		var res=getCookie("res");
		         		if(res!=null&&res!=""){
		         			res=$.parseJSON(res);
		         			console.log(res)
		         			var str="";
		         			var sum=0;
		         			var sumjifen=0;//总积分
		         			$.each(res.result,function(index,val1){
		         				var goodlist='';
		         				if(this.goods_list!=null&&this.goods_list.length!=0){
		         					$.each(this.goods_list, function(index,val) {
		         						sum+=this.goods_price*this.goods_num;
		         						sumjifen+=this.goods_point*this.goods_num;
		         						car_id+=this.cart_id+'_'+this.goods_num+',';
		         						var src=net+"public/uploads/home/store/goods/"+this.store_id+"/"+this.goods_image;
		         						goodlist+='<div class="ds-container"><img  src="'+src+'"/><div class="store-con"><h1 class="only-line" style="overflow: hidden;">'+this.goods_name+'<span class="order-p">￥'
		         						        +this.goods_price+'</span></h1><span class="gengxin">共'+this.goods_num+'件商品</span></span><span class="gm-jifen" style="color: #666666;">'+this.goods_point+'积分</span>'
		         				                +'<span class="gm-phone-icon" style="color: #666666;">x'+this.goods_num+'</span></div></div>'
		         					});
		         				}
		         				str+='<li><a data-href="" style="display: block;"><h2 class="ds-name">'+val1.store_name+'</h2>'+goodlist+'</a></li>'	
		         			})
		         			
		         			sum=Math.round(sum*100)/100;
		         			$("#money").html(sum)
		         			$("#pay-jifen").html('&nbsp;/&nbsp;'+sumjifen)
		         			$(".store-list").append(str)
	         			}
	         		}else if(ye=="2"){
         				//从cookie中获取订单商品信息
		         		var res=getCookie("res");
		         		if(res!=null&&res!=""){
		         			res=$.parseJSON(res);
		         			var str="";
		         			var sum=0;
		         			var sumjifen=0;//总积分
		         			$.each(res.result,function(index,val){
		         				var goodlist='';
		         				if(this.goods_list!=null&&this.goods_list.length!=0){
		         					$.each(this.goods_list, function(index,val) {
		         						$.each(val, function(index,val) {
			         						sum+=this.goods_price*this.goods_num;
			         						sumjifen+=this.goods_point*this.goods_num;
			         						car_id+=this.cart_id+'_'+this.goods_num+',';
			         						var src=net+"public/uploads/home/store/goods/"+this.store_id+"/"+this.goods_image;
			         						goodlist+='<div class="ds-container"><img  src="'+src+'"/><div class="store-con"><h1 class="only-line" style="overflow: hidden;">'+this.goods_name+'<span class="order-p">￥'
			         						        +this.goods_price+'</span></h1><span class="gengxin">共'+this.goods_num+'件商品</span></span><span class="gm-jifen" style="color: #666666;">'+this.goods_point+'积分</span>'
			         				                +'<span class="gm-phone-icon" style="color: #666666;">x'+this.goods_num+'</span></div></div>'
		         					    });
		         					});
		         				}
		         				str+='<li><a data-href="" style="display: block;"><h2 class="ds-name">'+this.store_name+'</h2>'+goodlist+'</a></li>'	
		         			})
		         			
		         			sum=Math.round(sum*100)/100;
		         			$("#money").html(sum)
		         			$("#pay-jifen").html('&nbsp;/&nbsp;'+sumjifen)
		         			$(".store-list").append(str)
	         			}
	         		}
         		}
         		//点击确认按钮生成订单
         		$(".zhifu-container1").on("tap",".jiao-btn",function(){
         			var pay_param = {};
         			pay_param.member_id = userid;
         			var reg = /,$/gi;
                    car_id=car_id.replace(reg,"");//截去字符串最后的逗号
         			if(car_id==null||car_id==""){
         				alert("网络错误");
         				return false;
         			}
         			pay_param.cart_id=car_id;
         			pay_param.address_id=$("#addressid").val();
         			if(pay_param.address_id==""||pay_param.address_id==null)
         			{
         				alert("您还没有填收货地址")
         				location.href="address.html?type=1";
         			}
         			$(".zhifu-type").each(function(i){
                     	if($(this).attr("flag")=="1"){
                     		pay_param.payment_code = $(this).attr("type")
                     		if($(this).attr("type") == "alipay_app"){
                     			channel=aliChannel;
                     		}else if($(this).attr("type") == "wxpay_app"){
                     			channel=wxChannel;
                     		}
        
                     	}
                     })
//       			plus.nativeUI.showWaiting();
         			if(ye=="1"){
         				pay_param.ifcart="1";
         			}
         			//请求接口
         			$.post(net+"/public/index.php?s=api/buy/buy_step2",pay_param,function(res){
         				if(pay_param.payment_code=="point"&&res.code=="200"){
         					$.ajax({
							    type: "post",
							    async: false,
							    url: net+"/public/index.php?s=api/Payment/order_pay/",
							    data: res.result,
							    success: function(res){
							    	if(res.code==200){
							    		 alert("积分支付成功");
							    		 mui.openWindow({url:"order2.html"})
							    	}else{
							    		 alert(res.message);
							    	}
							        
//	       							
							    },
							    error: function(error){
							        callback({'code':1,'msg':"网络连接错误"});
							        return false;
							    }
							});
//       					mui.openWindow({url:"order2.html"})
         				}else if(res.code=="1000110"){
         					alert("积分不足，请选择其他方式支付")
         				}else if(pay_param.payment_code!="point"&&res.code=="200"){
         					$.ajax({
						        type: "post",
						        async: false,
						        url: net+"/public/index.php?s=api/Payment/order_pay/",
						        data: res.result,
						        success: function(res){
//							      	alert(JSON.stringify(res))
	       							plus.nativeUI.closeWaiting();  
								      	checkServices(channel)
								        plus.payment.request(channel,res.result, function(result) {
	                                        mui.openWindow({url:"order2.html"})
								        }, function(e) {
//								        	alert(JSON.stringify(e))
								        	alert("支付失败")
								        });   						  
						        },
						        error: function(error){
						            callback({'code':1,'msg':"网络连接错误"});
						            return false;
						        }
							});


         					
         				}
         			})
         		})
			}
		})
		
        
		</script>
	</body>

</html>